package cate.common.table.activity.skindraw.row;

import cate.common.annotation.SplitParse;
import cate.common.table.EExcelNoteField;
import cate.common.table.EExcelRowClass;
import cate.common.table.ERow;
import cate.common.util.SplitParser;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@EExcelRowClass(IDTitle = "配置ID")
public class SkinDrawBaseRow extends ERow {
    @EExcelNoteField(fieldName = "单抽消耗")
    public String oneCost;
    @EExcelNoteField(fieldName = "十连消耗")
    public String tenCost;
    @EExcelNoteField(fieldName = "正常奖励分组")
    public int normalGroup;
    @EExcelNoteField(fieldName = "充值金额",defaultValue = "0")
    public int recharge;
    @EExcelNoteField(fieldName = "防脸白稀有抽取次数",defaultValue = "0")
    public int minTimes;
    @EExcelNoteField(fieldName = "充值奖池分组")
    public int rechargeGroup;
    @EExcelNoteField(fieldName = "保底次数",defaultValue = "0")
    public int cheatTime;
    @EExcelNoteField(fieldName = "保底奖励分组")
    public int cheatGroup;
    @EExcelNoteField(fieldName = "次数奖励分组")
    public int timesGroup;
    @EExcelNoteField(fieldName = "每日钻石次数",defaultValue = "-1")
    public int diaTimes;
    @EExcelNoteField(fieldName = "钻石单抽消耗")
    public String diaCost;
    @EExcelNoteField(fieldName = "赠送经验")
    public String exp;
    @EExcelNoteField(fieldName = "每日免费次数上限")
    public int limit;
    @EExcelNoteField(fieldName = "十连稀有个数",defaultValue = "0")
    public int rare;
    @EExcelNoteField(fieldName = "可更换稀有组")
    public String rareList;
    @EExcelNoteField(fieldName = "保底奖励权重")
    public String cheatStr;

    @EExcelNoteField(fieldName = "跑马灯公告", defaultValue = "0")
    public int lampId;

    public List<PickSellParam> pickSellParams;

    @NoteClass(value = "可更换稀有组权重配置")
    public static final class PickSellParam {
        @SplitParse(order = 0)
        public int type;

        @SplitParse(order = 1)
        public int sellTid;

        @SplitParse(order = 2, defaultValue = "1")
        public int num;

        @SplitParse(order = 3, defaultValue = "0")
        public double weight;
    }

    public PickSellParam getParam(int id) {
        return pickSellParams.stream().filter(param -> param.sellTid == id).findAny().orElse(null);
    }

    @Override
    public void decode() {
        pickSellParams = new ArrayList<>();
        if (StringUtils.isNotBlank(this.rareList)) {
            this.pickSellParams = SplitParser.parse(PickSellParam.class, this.rareList);
        }
    }

}
